<template>
  <el-card>
    <div slot="header">
      <span>分店榜单</span>
    </div>
    <el-table
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column
      label="分店">
      <template slot-scope="scope">
        {{scope.row.branchId | formatBranch}}
      </template>
    </el-table-column>
    <el-table-column
      prop="feedback"
      label="反馈数量"
      sortable>
    </el-table-column>
    <el-table-column
      label="满意度"
      >
      <template slot-scope="scope">
        {{scope.row.rate | formatPercent}}
      </template>
    </el-table-column>
  </el-table>
  </el-card>
</template>
<script>
import { getBranchRanking } from "@/api/ranking";
import { formatDate } from "@/utils";
  export default {
    data() {
      return {
        tableData: []
      }
    },
    created() {
      this.initRanking()
    },
    methods: {
      initRanking() {
        getBranchRanking({
          shopId: sessionStorage.getItem('selected_shop_id'),
          // startDate: formatDate(new Date(), 'yyyy-mm-dd'),
          // endDate: formatDate(new Date(), 'yyyy-mm-dd')
        }).then(res => {
          res.data.data.map(row => {
            row.rate = row.feedback / row.sum
            return row
          })
          this.tableData = res.data.data
        })
      }
    },
    formatter(row, column) {
      console.log(row)
      let value = row.rate
    if(!value) value = 0;
    let decimals = 0;
  
    value = value * 100;
    return Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals) + "%";
  }
  }
</script>